package com.zqr.lock;

import java.util.concurrent.TimeUnit;

/**
 * @author zqr
 * @since 2022/11/2
 */
public class VolatileDemo {
    private static volatile boolean flag = true;

    public static void main(String[] args) throws InterruptedException {
        new Thread(() -> {
            int i = 0;
            while (flag) {
                i++;
/*                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }*/
            }
            System.out.println("线程执行结束");
        }).start();

        TimeUnit.SECONDS.sleep(1);
        flag = false;
    }
}
